package com.skivingcloud.workflow.service.impl;

import com.skivingcloud.common.utils.PageUtils;
import com.skivingcloud.workflow.entity.DepolymentInfo;
import com.skivingcloud.workflow.entity.ProcessVO;
import com.skivingcloud.workflow.mapper.DepolymentInfoMapper;
import com.skivingcloud.workflow.service.IDepolymentInfoService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author skivingcloud
 * @since 2022-03-03
 */
@Service
public class DepolymentInfoServiceImpl extends ServiceImpl<DepolymentInfoMapper, DepolymentInfo> implements IDepolymentInfoService {

	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		int page = Integer.parseInt(params.get("page").toString());
		int limit = Integer.parseInt(params.get("limit").toString());
		params.put("page", (page - 1) * limit);
		params.put("limit", limit);
		List<DepolymentInfo> deploymentInfoList = this.baseMapper.selectPage(params);
		Integer count = this.baseMapper.count(params);
		List<ProcessVO> processVOList = new ArrayList<>(deploymentInfoList.size());
		deploymentInfoList.stream().forEach(wfDeploymentInfo -> {
			ProcessVO processVO = new ProcessVO(wfDeploymentInfo.getProcessDefinition());
			processVO.setDeployTime(wfDeploymentInfo.getDeployment().getDeploymentTime());
			processVO.setUsername(wfDeploymentInfo.getUser() != null ? wfDeploymentInfo.getUser().getUsername() : null);
			processVOList.add(processVO);
		});
		return new PageUtils(processVOList, count);
	}
}
